<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Ajax获取Sina Weibo的内容, 用于显示在边侧栏.
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.1
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_weibo.php';

// Definitions.
define('WEIBO_ITEMS_COUNT',			10);


class GetweibohtmlAction extends Action
{
	/**
	 * Weibo id.
	 */
	var $weibo_id;
	
	function prepare($args)
	{
		parent::prepare($args);
		
		// Parameter from 'get' url
		$this->weibo_id = $this->getTrimmedArg('gweibo_id');
		
		if ( !is_numeric($this->weibo_id)) {
			return false;
		}
		
		return true;
	}
	
	function handle($args)
	{
		parent::handle($args);

		// Return the html code.
		$output  = '<ul>';

		// 这里从一个新浪小组件里调用数据来源可以减少一定的数据流也可以避免跳到登陆页
		$contents  = file_get_contents('http://v.t.sina.com.cn/widget/widget_blog.php?uid='. $this->weibo_id .'');
		$tempItemContent  = explode('<p class="wgtCell_txt">', $contents);
		$tempItemTime  = explode('<span class="wgtCell_tm">', $contents);
		for($n = 1; $n <= WEIBO_ITEMS_COUNT; $n++) {
			$content  = explode('</p>', $tempItemContent[$n]);
			$time  = explode('</span>', $tempItemTime[$n]);
			$output .= '<li>' . $content[0] . '<p>' . $time[0] . '</p>' . '</li>';
		}
		
		$output .= '</ul>';
		
		$this->raw($output);
	}
}

?>